package com.example.javaspringweb.controller;

import com.example.javaspringweb.entity.UserDemo;
import com.example.javaspringweb.service.UserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserController {

    @Resource
    private UserServiceImpl userServiceImpl;

    @GetMapping("/userA")  // @RequestMapping(method = RequestMethod.GET)的缩写。
    public String getAllData(Model model) {
        List<UserDemo> allUser = userServiceImpl.findAllUser();
        model.addAttribute("allUser", allUser);
        return "user/user_a";
    }

    @GetMapping("/addUser")
    public String addUserData(
            @RequestParam String username,
            @RequestParam String userpassword,
            Model model
    ){
        userServiceImpl.addUser(username, userpassword);
        model.addAttribute("addUser", "成功");
        return "user/user_b";
    }


}

